
// 混合开发
// 将公共功能抽离出来
import MyBreadcrumb from '../components/MyBreadcrumb.vue';

import { httpGoods } from '../api/goods'

export default {
    data() {
        return {
            tableData: [],
            goodsObj: {
                query: '',
                pagenum: 1,
                pagesize: 2
            },
            total: 0,
        }
    },
    components: {
        MyBreadcrumb,
    },
    created() {
        this.initGoods();
    },
    methods: {
        async initGoods() {
            const res = await httpGoods("/goods", this.goodsObj);
            this.tableData = res.data.data.goods;
            this.total = res.data.data.total;
        },
        pageChange(obj) {
            if (obj.type === 'size') {
                this.goodsObj.pagesize = obj.val
            } else {
                this.goodsObj.pagenum = obj.val
            }
            this.initGoods();
        },
        // 搜索
        initSearch() {
            this.initGoods();
        },
        // 跳转到添加商品页面
        addGoods() {
            this.$router.push('/add')
        },
    }
}